/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import libCore.Util;
import models.U_EggModel;
import share.ShareMacros;
/**
 *
 * @author LinhTA 
 */
public class Box_Egg implements EntityBase{
    
    public int level;
    public Map<String,Egg> eggs = new HashMap<String, Egg>();
    
     @Override 
    public Map<String,Object> toAMF()
    {
        Map<String,Object> data = new HashMap<String, Object>();
        
        data.put(ShareMacros.LEVEL, level);
        data.put(ShareMacros.EGGS,U_EggModel.toAMF(eggs));
        
        return data;
    }
    
    @Override 
    public void setData(Map<String, Object> obj)
        {
            Map<String,Object> data = Util.obj2Map(obj);
            
            level = Integer.parseInt(data.get(ShareMacros.LEVEL).toString());
            
            Map<String,Object> dataEggs = Util.obj2Map(data.get(ShareMacros.EGGS));
            for (Map.Entry<String, Object> dataEgg : dataEggs.entrySet()) {
                String string = dataEgg.getKey();
                Object object = dataEgg.getValue();
                
                Egg e = new Egg();
                e.setData(Util.obj2Map(object));
                eggs.put(string, e);
            }
        }
    
    public static class BoxEggDB
    {
        public String level;
        public String eggs;
        
        public BoxEggDB(){
        }
        
        public void setData(Map<String, String> obj) {
            level   =   String.valueOf( obj.get(ShareMacros.LEVEL) );
            eggs    =   obj.get(ShareMacros.EGGS);
        }
    }
}
